package com.pureut.storage.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.core.utils.bean.BeanUtils;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.PickingOutsourceDetail;
import com.pureut.storage.dto.PickingOutsourceDetailDto;
import com.pureut.storage.mapper.PickingOutsourceDetailMapper;
import com.pureut.storage.service.PickingOutsourceDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: CM
 * @date: 2023/1/31  9:57
 */
@Service
public class PickingOutsourceDetailServiceImpl extends ServiceImpl<PickingOutsourceDetailMapper,PickingOutsourceDetail> implements PickingOutsourceDetailService {

    @Resource
    PickingOutsourceDetailMapper pickingOutsourceDetailMapper;

    /**
     * 委外发货明细列表
     * @param docNum
     * @return
     */
    @Override
    public List<PickingOutsourceDetailDto> getList(String docNum) {
        //获取单据状态字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_outsource_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        List<PickingOutsourceDetailDto> list = pickingOutsourceDetailMapper.getPickDetailList(docNum);

        for (PickingOutsourceDetailDto pickingOutsourceDetailDto : list) {
            pickingOutsourceDetailDto.setStatusDict(pickingOutsourceDetailDto.getStatus());
            pickingOutsourceDetailDto.setStatus(statusMap.get(pickingOutsourceDetailDto.getStatus()));
        }
        return list;
    }
}
